<?php
namespace app\home\controller;

use app\home\common\Common;
use app\home\common\Page;
use app\home\common\Pagetwo;
use app\home\service\Smstmp;
use app\infrastructure\uri\Request;
use app\infrastructure\uri\Uri;
use think\Db;

/**
 * Created by PhpStorm.
 * User: YD
 * Date: 2017/4/26
 * Time: 16:52
 */
class User extends Common
{
    private $client;
    public  function  __construct(){
        parent::__construct();
        $this->client=new Request();
    }
    public function userList()
    {
        //获取短信推送模板
       $smsTmp=(new Smstmp())->getAppSmsTmp(1);
        $this->assign('smsTmp',$smsTmp);
        $get=$_GET;
        $query=[];
        if(session('role') == 'admin'){
            //线上
            $query['userPhone']=["NOT LIKE","1%"];
        }elseif(session('role') == 'testing'){
           //测试
            $query['userPhone']=["LIKE","1%"];
        }

        if(!empty($get['user_phone'])){
            $query['userPhone']=$get['user_phone'];
        }
        if(isset($get['sms_status'])){
            if($get['sms_status'] == 11){
                $query['admin_sms_status']=["IN",[0,1,2,3]];
            }else{
                $query['admin_sms_status']=$get['sms_status'];
            }
        }else{
            $query['admin_sms_status']=["IN",[0,1,2,3]];
        }
        if(isset($get['gender']) && $get['gender'] != ''){
            if($get['gender'] == 0){

            }else{
                $query['gender']=$get['gender'];
            }
        }
        if(!empty($get['startBirth'])){
            $query['birthDay']=["EGT",$get['startBirth']];
        }
        if(!empty($get['endBirth'])){
            $query['birthDay']=['ELT',$get['endBirth']];
        }
        if(!empty($get['startBirth']) && !empty($get['endBirth'])){
            $query['birthDay'][]=['EGT',$get['startBirth']] ;
            $query['birthDay'][]=['ELT',$get['endBirth']] ;
        }

        if(!empty($get['signStart'])){
            $query['create_time']=[
                'EGT',strtotime($get['signStart'])*1000
            ];
        }
        if(!empty($get['signEnd'])){
            $query['create_time']=[
                'ELT',strtotime($get['signEnd'])*1000
            ];
        }
        if(!empty($get['signStart']) && !empty($get['signEnd'])){
            $query['create_time'][]=[
                'EGT',strtotime($get['signStart'])*1000
            ];
            $query['create_time'][]=[
                'ELT',strtotime($get['signEnd'])*1000
            ];
        }

//        $countUrl=Uri::HOST.Uri::POSTUSERLIST;
        $totalCount =Db::table("user")
            ->where($query)
            ->count();
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userPhone',
                    'status',
                    'inviteurl',
                    'invitor',
                    'admin_sms_status',
                    'create_time'
                ]
            ];
            $newTotalData=[];
            $totalCount=Db::table("user")
                ->where($query)
                ->order("create_time","DESC")
                ->field("id,userPhone,status,inviteurl,invitor,admin_sms_status,create_time")
                ->select();
            foreach($totalCount as $k=>$v){
                $newTotalData[]=[
                  'ID'=>$v['id'],
                  'userPhone'=>$v['userPhone'],
                  'status'=>$v['status'],
                  'inviteurl'=>$v['inviteurl'],
                  'invitor'=>$v['invitor'],
                  'admin_sms_status'=>$v['admin_sms_status'],
                  'create_time'=>date('Y-m-d H:i:s',strtotime($v['create_time']))
                ];
                if($v['admin_sms_status'] == 1){
                    $newTotalData[$k]['admin_sms_status']='pass';
                } elseif($v['admin_sms_status'] == 2){
                    $newTotalData[$k]['admin_sms_status']='nopass';
                }elseif($v['admin_sms_status'] == 3){
                    $newTotalData[$k]['admin_sms_status']='no SMS';
                }else{
                    $newTotalData[$k]['admin_sms_status']='no review';
                }
            }
            $data = array_merge($column_name, $newTotalData);
            $this->extendToExcel($data);
        }
        $data =Db::table("user")
            ->where($query)
            ->order("create_time","DESC")
            ->field("id,userPhone,status,inviteurl,invitor,admin_sms_status,create_time")
            ->paginate(15);
        $newData=[];
        foreach($data as $k=>$v){
            $newData[]=[
               "id"=>$v['id'],
               "userPhone"=>$v['userPhone'],
               "status"=>$v['status'],
               "inviteurl"=>$v['inviteurl'],
               "invitor"=>$v['invitor'],
               "admin_sms_status"=>$v['admin_sms_status'],
               "create_time"=>gmtToIndiaTimeByMysql($v['create_time'])
            ];
        }
        $page = $data->render();


        $this->assign('page',$page);

        $this->assign('data',$newData);
        $this->assign('totalCount',$totalCount);
        return view();
    }
    //用户详情
    public function userInfo(){
        $id=$_GET['uid'];
        $userUrl=Uri::HOST.Uri::USERLIST."?id=".$id;
        $user=$this->client->getArrayData($userUrl);
        if($user['code']!=0){
            $userData=[];
        }else{
            $userData=$user['data'][0];
        }
        $this->assign('data',$userData);
        return view();
    }
    /**
     * 用户通讯录
     */
    public function usercontact(){
        $get=$_GET;
        $query=[];
        if(!empty($get['contact_name'])){
            $query['contact_name']=[
                '$like'=>'%'.$get['contact_name'].'%'
            ];
        }
        $query['user_id']=$get['uid'];
        $query['limitation']=10000;
        $countUrl=Uri::HOST.Uri::SELECTUSERCONTACTPOSTNEW;
        $totalCount =$this->client->getArrayData($countUrl,$query,3);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'user id',
                    'user phone',
                    'contact_name',
                    'contact_phone_num',
                    'relation',
                    'record_time',
                    'create_time',
                    'update_time'
                ]
            ];
            $data = array_merge($column_name, $totalCount['data']);
            $this->extendToExcel($data);
        }
        $p=empty(input('p'))?1:input('p');
        $startIndex=($p-1)*10;
        $query['limitation']=10;
        $query['offset']=$startIndex;
        $value = $this->client->getArrayData($countUrl,$query,3);
        if($value['code'] != 0){
            $value['data']=[];
        }
        $pager=new Page(count($totalCount['data']),10,$p,['uid'=>$get['uid']]);
        $page=$pager->show();
        $this->assign('page',$page);
        $this->assign('data',$value['data']);
        $this->assign('totalCount',count($totalCount['data']));
        return view();
    }
    /**
     * 用户短信
     */
    public function usersms(){
        $get=$_GET;
        $query=[];
        if(!empty($get['sendStart'])){
            $query['send_time']=[
                '$gte'=>strtotime($get['sendStart'])*1000
            ];
        }
        if(!empty($get['sendEnd'])){
            $query['send_time']=[
                '$lte'=>strtotime($get['sendEnd'])*1000
            ];
        }
        if(!empty($get['sendStart']) && !empty($get['sendEnd'])){
            $query['send_time']=[
                '$gte'=>strtotime($get['sendStart'])*1000,
                '$lte'=>strtotime($get['sendEnd'])*1000
            ];
        }

        if(!empty($get['sms_content'])){
            $query['sms_content']=[
                '$like'=>'%'.$get['sms_content'].'%'
            ];
        }
        $query['user_id']=$get['uid'];
        $query['limitation']=10000;
         $countUrl=Uri::HOST.Uri::SELECTUSERSMSPOSTNEW;
        $totalCount =$this->client->getArrayData($countUrl,$query,3);
        $p=empty(input('p'))?1:input('p');
        $startIndex=($p-1)*10;
        $query['limitation']=10;
        $query['offset']=$startIndex;
        $value = $this->client->getArrayData($countUrl,$query,3);
        if($value['code'] != 0){
            $value['data']=[];
        }
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'user id',
                    'user phone',
                    'from_phone_num',
                    'from_user_name',
                    'sms_content',
                    'send_time',
                    'plantform',
                    'create_time',
                    'update_time'
                ]
            ];
            $data = array_merge($column_name, $totalCount['data']);
            $this->extendToExcel($data);
        }
        $pager=new Page(count($totalCount['data']),10,$p,['uid'=>$get['uid']]);
        $page=$pager->show();
        $this->assign('page',$page);
        $this->assign('data',$value['data']);
        $this->assign('totalCount',count($totalCount['data']));
        return view();
    }
    /**
     * 用户app使用历史
     */
    public function userappuse(){
        $get=$_GET;
        $query=[];
        if(!empty($get['app_name'])){
            $query['app_name']=[
                '$like'=>'%'.$get['app_name'].'%'
            ];
        }
        $query['user_id']=$get['uid'];
        $query['limitation']=10000;
        $countUrl=Uri::HOST.Uri::SELECTUSERAPPUSEPOSTNEW;
        $totalCount =$this->client->getArrayData($countUrl,$query,3);
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'user id',
                    'user phone',
                    'app_name',
                    'app_version',
                    'app_provider',
                    'app_install_time',
                    'app_remove_time',
                    'type',
                    'create_time',
                    'update_time'
                ]
            ];
            $data = array_merge($column_name, $totalCount['data']);
            $this->extendToExcel($data);
        }
        $p=empty(input('p'))?1:input('p');
        $startIndex=($p-1)*10;
        $query['limitation']=10;
        $query['offset']=$startIndex;
        $value = $this->client->getArrayData($countUrl,$query,3);
        if($value['code'] != 0){
            $value['data']=[];
        }
        $pager=new Page(count($totalCount['data']),10,$p);
        $page=$pager->show();
        $this->assign('page',$page);
        $this->assign('data',$value['data']);
        $this->assign('totalCount',count($totalCount['data']));
        return view();
    }

    /**
     * 人脸识别
     */
    public function userface(){
        $id=$_GET['uid'];
        $userPhone=$_GET['phoneNum'];
        $url=Uri::HOST.Uri::SELECTUSERFACE."?user_id=".$id;
        $userFace=$this->client->getArrayData($url);
        if($userFace['code'] != 0){
            $userFace=[];
        }else{
            $userFace=$userFace['data'][0];
            $userFace['photo']=json_decode($userFace['photo']);
            $userFace['result']=json_decode($userFace['result']);
            if(isset($userFace['result'])){
                $userFace['confidence']=$userFace['result']->confidence;
            }else{
                $userFace['confidence']='';
            }
        }
        //个人认证
        $personUrl=Uri::HOST.Uri::USERCERITYS."?phoneNumber=".$userPhone;
        $person=$this->client->getArrayData($personUrl);
        if(empty($person['data'])){
            $person=[];
        }else{
            $person=$person['data'][0];
        }

        $this->assign('person',$person);
//        dd($person);


//        dd($userFace);die;
//        foreach($userFace['data'] as $k=>$v){
//            if(strlen($userFace['data'][$k]['result'])>20){
//                $tmp=json_decode($userFace['data'][$k]['result']);
////                dd($tmp);
//                if(isset($tmp->confidence)){
//                    $userFace['data'][$k]['confidence']=$tmp->confidence;
//                }else{
//                    $userFace['data'][$k]['confidence']='';
//                }
//
//            }else{
//                $userFace['data'][$k]['confidence']=$userFace['data'][$k]['result'];
//            }
//        }
//        dd($userFace);
        $this->assign('data',$userFace);
//        dd($userFace);
//        die;
        return view();
    }

    /**
     * 短信打标
     */
    public function updateUser(){
        if(\think\Request::instance()->isAjax()){
             $id=$_POST['uid'];
            $data=[
                'admin_sms_status'=>$_POST['admin_sms_status']
            ];
            $url=Uri::HOST.Uri::UPDATEUSER.$id;
            $userFace=$this->client->getArrayData($url,$data,4);
          return $userFace;
        }
    }

    /**
     * 用户认证
     */
    public function userCer(){
        $id=$_GET['uid'];
        $phoneNum=$_GET['phoneNum'];
        //个人认证
        $personUrl=Uri::HOST.Uri::USERCERITYS."?phoneNumber=".$phoneNum;
        $person=$this->client->getArrayData($personUrl);
        //公司认证
        $companyUrl=Uri::HOST.Uri::USERCOMPANYCERITYS."?userID=".$id;
        $company=$this->client->getArrayData($companyUrl);
        //addr认证
//        $addrUrl=Uri::HOST.Uri::FINDAADHAARS."?userID=".$id;
//        $addr=$this->client->getArrayData($addrUrl);
        //个人信息
        $personInfoUrl=Uri::HOST.Uri::SELECTPERSONINFO."?user_id=".$id;
        $personInfo=$this->client->getArrayData($personInfoUrl);
        //银行卡信息
        $bankUrl=Uri::HOST.Uri::SELECTUSERBANK.$id;
        $userBank=$this->client->getArrayData($bankUrl);
        //查找历史银行卡信息
        //历史无效银行卡
        $useraccountListUrl=Uri::HOST.Uri::SELECTACCOUNT."?user_id=".$id."&is_valid=0";
        $useraccountList=$this->client->getArrayData($useraccountListUrl);


        if(empty($person['data'])){
            $person=[];
        }else{
            $person=$person['data'][0] ;
        }
        if(empty($company['data'])){
            $company=[];
        }else{
            $company=$company['data'][0] ;
        }
        if(empty($addr['data'])){
            $addr=[];
        }else{
            $addr=$addr['data'][0] ;
        }

        if(empty($personInfo['data'])){
            $personInfo=[];
        }else{
            $personInfo=$personInfo['data'][0] ;
        }

        if(empty($userBank['data'])){
            $userAccount=[];
        }else{
            $userAccount=$userBank['data'];
        }

       if(empty($useraccountList['data'])){
           $useraccountList=[];
        }else{
           $useraccountList=$useraccountList['data'];
        }

//         dd($person);
//         dd($company);
//         dd($personInfo);
        $this->assign('userAccount',$userAccount);
        $this->assign('useraccountList',$useraccountList);
        $this->assign('userCerInfo',$person);
        $this->assign('companyCerInfo',$company);
//        $this->assign('aadhaarCerInfo',$addr);
        $this->assign('personInfo',$personInfo);
        return view();
    }

    /**
     * 完成个人信息
     */
    public function personedList(){
        $url= Uri::HOST.Uri::SELECTPERSONINFO."?limitation=100000";
        $personal= $this->client->getArrayData($url);
        $personal=$personal['data'];
        $personalUser=[];
        $phoneTestPreg='/^1{7}[0-9]{3}/';//匹配1111111***
        $chinaPhone='/^1[0-9]{9}[0-9]$/';//匹配中国的手机号
        foreach($personal as $k=>$v){
            if(session('role') == 'admin'){
                if(!preg_match($phoneTestPreg,$v['user_phone'])){
                    if(!preg_match($chinaPhone,$v['user_phone'])){
                        $personalUser[]=$v['user_phone'];
                    }
                }
            }else if(session('role') == "testing"){
                if(preg_match($phoneTestPreg,$v['user_phone'])){
                    if(preg_match($chinaPhone,$v['user_phone'])){
                        $personalUser[]=$v['user_phone'];
                    }
                }
            }
        }
        //获取短信推送模板
        $smsTmp=(new Smstmp())->getAppSmsTmp(1);
        $this->assign('smsTmp',$smsTmp);
//        dd($smsTmp);
        $get=$_GET;
        $query=[];
        $query['userPhone']=$personalUser;
        if(!empty($get['user_phone'])){
            $query['userPhone']=$get['user_phone'];
        }
        if(isset($get['sms_status'])){
            if($get['sms_status'] == 11){
                $query['admin_sms_status']=[0,1,2,3];
            }else{
                $query['admin_sms_status']=$get['sms_status'];
            }
        }else{
            $query['admin_sms_status']=[0,1,2,3];
        }
        if(isset($get['gender']) && $get['gender'] != ''){
            if($get['gender'] == 0){

            }else{
                $query['gender']=$get['gender'];
            }
        }
        if(!empty($get['startBirth'])){
            $query['birthDay']=[
                '$gte'=>$get['startBirth']
            ];
        }
        if(!empty($get['endBirth'])){
            $query['birthDay']=[
                '$lte'=>$get['endBirth']
            ];
        }
        if(!empty($get['startBirth']) && !empty($get['endBirth'])){
            $query['birthDay']=[
                '$gte'=>$get['startBirth'],
                '$lte'=>$get['endBirth']
            ];
        }
        if(!empty($get['signStart'])){
            $query['create_time']=[
                '$gte'=>strtotime($get['signStart'])*1000
            ];
        }
        if(!empty($get['signEnd'])){
            $query['create_time']=[
                '$lte'=>strtotime($get['signEnd'])*1000
            ];
        }
        if(!empty($get['signStart']) && !empty($get['signEnd'])){
            $query['create_time']=[
                '$gte'=>strtotime($get['signStart'])*1000,
                '$lte'=>strtotime($get['signEnd'])*1000
            ];
        }
        $query['limitation']=1000000;
        $countUrl=Uri::HOST.Uri::POSTUSERLIST;
        $totalCount =$this->client->getArrayData($countUrl,$query,3);

        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userPhone',
                    'status',
                    'inviteurl',
                    'invitor',
                    'admin_sms_status',
                    'create_time'
                ]
            ];
            $newTotalData=[];
            foreach($totalCount['data'] as $k=>$v){
                $newTotalData[]=[
                    'ID'=>$v['id'],
                    'userPhone'=>$v['userPhone'],
                    'status'=>$v['status'],
                    'inviteurl'=>$v['inviteurl'],
                    'invitor'=>$v['invitor'],
                    'admin_sms_status'=>$v['admin_sms_status'],
                    'create_time'=>date('Y-m-d H:i:s',strtotime($v['create_time']))
                ];
                if($v['admin_sms_status'] == 1){
                    $newTotalData[$k]['admin_sms_status']='pass';
                } elseif($v['admin_sms_status'] == 2){
                    $newTotalData[$k]['admin_sms_status']='nopass';
                }elseif($v['admin_sms_status'] == 3){
                    $newTotalData[$k]['admin_sms_status']='no SMS';
                }else{
                    $newTotalData[$k]['admin_sms_status']='no review';
                }
            }
            $data = array_merge($column_name, $newTotalData);
            $this->extendToExcel($data);
        }
        $p=empty(input('p'))?1:input('p');
        $startIndex=($p-1)*15;
        $query['limitation']=15;
        $query['offset']=$startIndex;
        $value = $this->client->getArrayData($countUrl,$query,3);
        if($value['code'] != 0){
            $value['data']=[];
        }
        foreach($value['data'] as $k=>$v){
            //查询个人认证信息
            $value['data'][$k]['create_time']=date('Y-m-d H:i:s',strtotime($v['create_time']));
            $userCerUrl=Uri::HOST.Uri::USERCERITYS."?phoneNumber=".$v['userPhone'];
            $userCerInfo=$this->client->getArrayData($userCerUrl);
            if(!empty($userCerInfo['data'])){
                $value['data'][$k]['userName']=$userCerInfo['data'][0]['firstname'].$userCerInfo['data'][0]['middlename'].$userCerInfo['data'][0]['lastname'];
            }else{
                $value['data'][$k]['userName']='';
            }
        }
        $pager=new Page(count($totalCount['data']),15,$p);
        $page=$pager->show();
        $this->assign('page',$page);
        $this->assign('data',$value['data']);
        $this->assign('totalCount',count($totalCount['data']));
        return view();
    }

    /**
     * 完成个人认证
     */
    public function userCerList(){
        $personal= Db::table('usercertifies')->field('phoneNumber')->select();
//        dd($personal);die;
        $personalUser=[];
        $phoneTestPreg='/^1{7}[0-9]{3}/';//匹配1111111***
        $chinaPhone='/^1[0-9]{9}[0-9]$/';//匹配中国的手机号
        foreach($personal as $k=>$v){
            if(session('role') == 'admin'){
                if(!preg_match($phoneTestPreg,$v['phoneNumber'])){
                    if(!preg_match($chinaPhone,$v['phoneNumber'])){
                        $personalUser[]=$v['phoneNumber'];
                    }
                }
            }else if(session('role') == "testing"){
                if(preg_match($phoneTestPreg,$v['phoneNumber'])){
                    if(preg_match($chinaPhone,$v['phoneNumber'])){
                        $personalUser[]=$v['phoneNumber'];
                    }
                }
            }
        }
        //获取短信推送模板
        $smsTmp=(new Smstmp())->getAppSmsTmp(1);
        $this->assign('smsTmp',$smsTmp);
//        dd($smsTmp);
        $get=$_GET;
        $query=[];
        $query['userPhone']=$personalUser;
        if(!empty($get['user_phone'])){
            $query['userPhone']=$get['user_phone'];
        }
        if(!empty($get['sms_status'])){
            $query['admin_sms_status']=$get['sms_status'];
        }
        if(isset($get['gender']) && $get['gender'] != ''){
            if($get['gender'] == 0){

            }else{
                $query['gender']=$get['gender'];
            }
        }
        if(!empty($get['startBirth'])){
            $query['birthDay']=[
                '$gte'=>$get['startBirth']
            ];
        }
        if(!empty($get['endBirth'])){
            $query['birthDay']=[
                '$lte'=>$get['endBirth']
            ];
        }
        if(!empty($get['startBirth']) && !empty($get['endBirth'])){
            $query['birthDay']=[
                '$gte'=>$get['startBirth'],
                '$lte'=>$get['endBirth']
            ];
        }
        if(!empty($get['signStart'])){
            $query['create_time']=[
                '$gte'=>strtotime($get['signStart'])*1000
            ];
        }
        if(!empty($get['signEnd'])){
            $query['create_time']=[
                '$lte'=>strtotime($get['signEnd'])*1000
            ];
        }
        if(!empty($get['signStart']) && !empty($get['signEnd'])){
            $query['create_time']=[
                '$gte'=>strtotime($get['signStart'])*1000,
                '$lte'=>strtotime($get['signEnd'])*1000
            ];
        }

        $query['limitation']=1000000;
        $countUrl=Uri::HOST.Uri::POSTUSERLIST;
        $totalCount =$this->client->getArrayData($countUrl,$query,3);

        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userPhone',
                    'status',
                    'inviteurl',
                    'invitor',
                    'admin_sms_status',
                    'create_time'
                ]
            ];
            $newTotalData=[];
            foreach($totalCount['data'] as $k=>$v){
                $newTotalData[]=[
                    'ID'=>$v['id'],
                    'userPhone'=>$v['userPhone'],
                    'status'=>$v['status'],
                    'inviteurl'=>$v['inviteurl'],
                    'invitor'=>$v['invitor'],
                    'admin_sms_status'=>$v['admin_sms_status'],
                    'create_time'=>date('Y-m-d H:i:s',strtotime($v['create_time']))
                ];
                if($v['admin_sms_status'] == 1){
                    $newTotalData[$k]['admin_sms_status']='pass';
                } elseif($v['admin_sms_status'] == 2){
                    $newTotalData[$k]['admin_sms_status']='nopass';
                }elseif($v['admin_sms_status'] == 3){
                    $newTotalData[$k]['admin_sms_status']='no SMS';
                }else{
                    $newTotalData[$k]['admin_sms_status']='no review';
                }
            }
            $data = array_merge($column_name, $newTotalData);
            $this->extendToExcel($data);
        }
        $p=empty(input('p'))?1:input('p');
        $startIndex=($p-1)*15;
        $query['limitation']=15;
        $query['offset']=$startIndex;
        $value = $this->client->getArrayData($countUrl,$query,3);
        if($value['code'] != 0){
            $value['data']=[];
        }
        foreach($value['data'] as $k=>$v){
            //查询个人认证信息
            $value['data'][$k]['create_time']=date('Y-m-d H:i:s',strtotime($v['create_time']));
            $userCerUrl=Uri::HOST.Uri::USERCERITYS."?phoneNumber=".$v['userPhone'];
            $userCerInfo=$this->client->getArrayData($userCerUrl);
            if(!empty($userCerInfo['data'])){
                $value['data'][$k]['userName']=$userCerInfo['data'][0]['firstname'].$userCerInfo['data'][0]['middlename'].$userCerInfo['data'][0]['lastname'];
            }else{
                $value['data'][$k]['userName']='';
            }
        }
        $pager=new Page(count($totalCount['data']),15,$p);
        $page=$pager->show();
        $this->assign('page',$page);
        $this->assign('data',$value['data']);
        $this->assign('totalCount',count($totalCount['data']));
        return view();
    }

    /**
     * 完成公司认证
     */
    public function companyCerList(){
        $url= Uri::HOST.Uri::USERCOMPANYCERITYS."?limitation=100000";
        $personal= $this->client->getArrayData($url);
        $personal=$personal['data'];
        $personalUser=[];
//        dd($personal);
        $phoneTestPreg='/^1{7}[0-9]{3}/';//匹配1111111***
        $chinaPhone='/^1[0-9]{9}[0-9]$/';//匹配中国的手机号
        foreach($personal as $k=>$v){
            if(session('role') == 'admin'){
                if(!preg_match($phoneTestPreg,$v['userPhone'])){
                    if(!preg_match($chinaPhone,$v['userPhone'])){
                        $personalUser[]=$v['userPhone'];
                    }
                }
            }else if(session('role') == "testing"){
                if(preg_match($phoneTestPreg,$v['userPhone'])){
                    if(preg_match($chinaPhone,$v['userPhone'])){
                        $personalUser[]=$v['userPhone'];
                    }
                }
            }
        }
//        dd($personalUser);
        //获取短信推送模板
        $smsTmp=(new Smstmp())->getAppSmsTmp(1);
        $this->assign('smsTmp',$smsTmp);
//        dd($smsTmp);
        $get=$_GET;
        $query=[];
        $query['userPhone']=$personalUser;
        if(!empty($get['user_phone'])){
            $query['userPhone']=$get['user_phone'];
        }
        if(isset($get['sms_status'])){
            if($get['sms_status'] == 11){
                $query['admin_sms_status']=[0,1,2,3];
            }else{
                $query['admin_sms_status']=$get['sms_status'];
            }
        }else{
            $query['admin_sms_status']=[0,1,2,3];
        }
        if(isset($get['gender']) && $get['gender'] != ''){
            if($get['gender'] == 0){

            }else{
                $query['gender']=$get['gender'];
            }
        }
        if(!empty($get['startBirth'])){
            $query['birthDay']=[
                '$gte'=>$get['startBirth']
            ];
        }
        if(!empty($get['endBirth'])){
            $query['birthDay']=[
                '$lte'=>$get['endBirth']
            ];
        }
        if(!empty($get['startBirth']) && !empty($get['endBirth'])){
            $query['birthDay']=[
                '$gte'=>$get['startBirth'],
                '$lte'=>$get['endBirth']
            ];
        }
        if(!empty($get['signStart'])){
            $query['create_time']=[
                '$gte'=>$get['signStart']*1000
            ];
        }
        if(!empty($get['signEnd'])){
            $query['create_time']=[
                '$lte'=>$get['signEnd']*1000
            ];
        }
        if(!empty($get['signStart']) && !empty($get['signEnd'])){
            $query['create_time']=[
                '$gte'=>$get['signStart']*1000,
                '$lte'=>$get['signEnd']*1000
            ];
        }
        $query['limitation']=1000000;
        $countUrl=Uri::HOST.Uri::POSTUSERLIST;
        $totalCount =$this->client->getArrayData($countUrl,$query,3);

        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userPhone',
                    'status',
                    'inviteurl',
                    'invitor',
                    'admin_sms_status',
                    'create_time'
                ]
            ];
            $newTotalData=[];
            foreach($totalCount['data'] as $k=>$v){
                $newTotalData[]=[
                    'ID'=>$v['id'],
                    'userPhone'=>$v['userPhone'],
                    'status'=>$v['status'],
                    'inviteurl'=>$v['inviteurl'],
                    'invitor'=>$v['invitor'],
                    'admin_sms_status'=>$v['admin_sms_status'],
                    'create_time'=>date('Y-m-d H:i:s',strtotime($v['create_time']))
                ];
                if($v['admin_sms_status'] == 1){
                    $newTotalData[$k]['admin_sms_status']='pass';
                } elseif($v['admin_sms_status'] == 2){
                    $newTotalData[$k]['admin_sms_status']='nopass';
                }elseif($v['admin_sms_status'] == 3){
                    $newTotalData[$k]['admin_sms_status']='no SMS';
                }else{
                    $newTotalData[$k]['admin_sms_status']='no review';
                }
            }
            $data = array_merge($column_name, $newTotalData);
            $this->extendToExcel($data);
        }
        $p=empty(input('p'))?1:input('p');
        $startIndex=($p-1)*15;
        $query['limitation']=15;
        $query['offset']=$startIndex;
        $value = $this->client->getArrayData($countUrl,$query,3);
        if($value['code'] != 0){
            $value['data']=[];
        }
        foreach($value['data'] as $k=>$v){
            //查询个人认证信息
            $value['data'][$k]['create_time']=date('Y-m-d H:i:s',strtotime($v['create_time']));
            $userCerUrl=Uri::HOST.Uri::USERCERITYS."?phoneNumber=".$v['userPhone'];
            $userCerInfo=$this->client->getArrayData($userCerUrl);
            if(!empty($userCerInfo['data'])){
                $value['data'][$k]['userName']=$userCerInfo['data'][0]['firstname'].$userCerInfo['data'][0]['middlename'].$userCerInfo['data'][0]['lastname'];
            }else{
                $value['data'][$k]['userName']='';
            }
        }
        $pager=new Page(count($totalCount['data']),15,$p);
        $page=$pager->show();
        $this->assign('page',$page);
        $this->assign('data',$value['data']);
        $this->assign('totalCount',count($totalCount['data']));
        return view();
    }


    /**
     * 未完成任何认证列表
     */
    public function noCerList(){
        if(session('role') == 'admin'){
//            $query['userPhone'][]=["exp",'REGEXP "^[0-9][0-9]{8}[0-9]$"'];
            $query['userPhone']=["NOT LIKE",'1%'];
        }else if(session('role') == 'testing'){
//            $query['userPhone'][]=["exp",'REGEXP "^1[0-9]{10}"'];
            $query['userPhone']=["LIKE",'1%'];
        }
         //完成个人信息
         $userPersonalInfo=Db::table('user_personalinfo')->column('user_phone');
        //完成个人认证
        $userCer=Db::table('usercertifies')->column('phoneNumber');
        //完成公司认证
        $userCom=Db::table('usercompcertifies')->column('userPhone');
        //完成人脸识别
        $userFace=Db::table('userface')->column('user_phone');
        $all=array_merge($userPersonalInfo,$userCer,$userCom,$userFace);
        $all=array_unique($all);
        $get=$_GET;
        if(!empty($get['user_phone'])){
            $query['userPhone']=$get['user_phone'];
        }
        if(isset($get['sms_status'])){
            if($get['sms_status'] == 11){
                $query['admin_sms_status']=['in',[0,1,2,3]];
            }
            else{
                $query['admin_sms_status']=$get['sms_status'];
            }
        }else{
            $query['admin_sms_status']=['in',[0,1,2,3]];
        }

        if(!empty($get['signStart'])){
            $startTime=date("Y-m-d H:i:s",(strtotime($get['signStart'])-5.5*3600));
            $query['create_time'][]=['egt',$startTime];
        }
        if(!empty($get['signEnd'])){
            $endTime=date("Y-m-d H:i:s",(strtotime($get['signEnd'])-5.5*3600));
            $query['create_time'][]=['elt',$endTime];
        }
        //用户列表
        $data=Db::table('user')->where('userPhone','not in',$all)
            ->where($query)
            ->field('id,userPhone,status,inviteurl,invitor,admin_sms_status,create_time')->order('create_time desc')->paginate(15);
//        dd(Db::table('user')->getLastSql());die;
        $totalUser=Db::table('user')->where('userPhone','not in',$all)
            ->where($query)
            ->field('id,userPhone,status,inviteurl,invitor,admin_sms_status,create_time')->count();

        if(isset($_GET['extend']) && $_GET['extend'] == 1) {
            $column_name = [
                [
                    'ID',
                    'userPhone',
                    'status',
                    'inviteurl',
                    'invitor',
                    'admin_sms_status',
                    'create_time'
                ]
            ];
            $data=Db::table('user')->where('userPhone','not in',$all)
                ->where($query)
                ->field('id,userPhone,status,inviteurl,invitor,admin_sms_status,create_time')->order('create_time desc')->select();
            $newData=[];
            foreach($data as $k=>$v){
                $newData[]=[
                    "id"=>$v['id'],
                    "userPhone"=>$v['userPhone'],
                    "status"=>$v['status'],
                    "inviteurl"=>$v['inviteurl'],
                    "invitor"=>$v['invitor'],
                    "admin_sms_status"=>$v['admin_sms_status'],
                    "create_time"=>$this->gmtToIndiaTimeByMysql($v['create_time'])
                ];
            }
            $data = array_merge($column_name, $newData);
            $this->extendToExcel($data);
        }
        $newData=[];

        foreach($data as $k=>$v){
            $newData[]=[
              "id"=>$v['id'],
              "userPhone"=>$v['userPhone'],
              "status"=>$v['status'],
              "inviteurl"=>$v['inviteurl'],
              "invitor"=>$v['invitor'],
              "admin_sms_status"=>$v['admin_sms_status'],
              "create_time"=>$this->gmtToIndiaTimeByMysql($v['create_time'])
            ];
        }
        $this->assign('data',$newData);
        $page = $data->render();
        $this->assign('page', $page);
        $this->assign('totalUser',$totalUser);
        return view();
    }

    /**
     * 认证完成列表
     */
    public function cerEdList(){
        if(session('role') == 'admin'){
//            $map['u.userPhone']=["exp",'REGEXP "^[0-9][0-9]{8}[0-9]$"'];
            $where['u.userPhone']=["NOT LIKE",'1%'];
        }else if(session('role') == 'testing'){
//            $map['u.userPhone']=["exp",'REGEXP "^1[0-9]{10}"'];
            $where['u.userPhone']=["LIKE",'1%'];
        }
        if(isset($_GET['gender']) && !empty($_GET['gender'])){
            if($_GET['gender'] == 1){
                $where['up.genderinfo']='male';
            }elseif($_GET['gender'] ==2){
                $where['up.genderinfo']="femail";
            }
        }
        if(isset($_GET['sms_status']) && !empty($_GET['sms_status'])){
                $where['u.admin_sms_status']=$_GET['sms_status'];
        }else if(isset($_GET['sms_status']) && $_GET['sms_status']==0){
            $where['u.admin_sms_status']=0;
        }else{
            $where['u.admin_sms_status']=["in","0,1,2,3"];
        }
        if(isset($_GET['user_phone']) && !empty($_GET['user_phone'])){
            $where['u.userPhone']=$_GET['user_phone'];
        }
        if(isset($_GET['signStart']) && !empty($_GET['signStart'])){
            $where['u.create_time']=["EGT",$_GET['signStart']];
        }
        if(isset($_GET['signEnd']) && !empty($_GET['signEnd'])){
            $where['u.create_time']=["ELT",$_GET['signEnd']];
        }

//        where('id','exp',' IN (1,3,8) ');
//        dd($where);
        $list=Db::name("user")->alias('u')
            ->join('user_personalinfo up','u.id = up.user_id',"RIGHT")
            ->join('Usercertifies uc','u.userPhone = uc.phoneNumber',"RIGHT")
            ->join('UserCompCertifies uco','u.id = uco.userID',"RIGHT")
            ->join('userface uf','u.id = uf.user_id',"RIGHT")
//            ->whereOr($map)
            ->where($where)
            ->order('u.create_time desc')
            ->distinct('u.id')
            ->field("u.id,u.userPhone,u.admin_sms_status,u.create_time uTime,up.create_time upTime,uc.createdAt ucTime,uc.firstname,uc.middlename,uc.lastname,uco.createdAt ucoTime,uf.create_time ufTime")
            ->paginate(15);

//        dd(Db::name("user")->getLastSql());
        $userId=[];
        foreach($list as $k=>$v){
            $userId[]=$v['id'];
        }
        $userId=array_unique($userId);
        foreach($list as $k=>$v){
            foreach($userId as $kk=>$vv){
                if($vv==$v['id']){
                    $newList[$v['id']]=$v;
                }
            }
        }
        foreach($newList as $k=>$v){
           $newList[$k]['uTime']=$this->gmtToIndiaTimeByMysql($v['uTime']);
           $newList[$k]['upTime']=$this->gmtToIndiaTimeByMysql($v['upTime']);
           $newList[$k]['ucTime']=$this->gmtToIndiaTimeByMysql($v['ucTime']);
           $newList[$k]['ucoTime']=$this->gmtToIndiaTimeByMysql($v['ucoTime']);
           $newList[$k]['ufTime']=$this->gmtToIndiaTimeByMysql($v['ufTime']);
        }
        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userPhone',
                    'admin_sms_status',
                    'createTime',
                    'personalInfoCreateTime',
                    'usercerityTime',
                    'firstName',
                    'middleName',
                    'lastName',
                    'companyCerTime',
                    'userFaceTime'
                ]
            ];
            $list=Db::name("user")->alias('u')
                ->join('user_personalinfo up','u.id = up.user_id')
                ->join('Usercertifies uc','u.userPhone = uc.phoneNumber')
                ->join('UserCompCertifies uco','u.id = uco.userID')
                ->join('userface uf','u.id = uf.user_id')
//                ->whereOr($map)
                ->where($where)
                ->order('u.create_time desc')
                ->distinct('u.id')
                ->field("u.id,u.userPhone,u.admin_sms_status,u.create_time uTime,up.create_time upTime,uc.createdAt ucTime,uc.firstname,uc.middlename,uc.lastname,uco.createdAt ucoTime,uf.create_time ufTime")
                ->select();
            $userId=[];
            foreach($list as $k=>$v){
                $userId[]=$v['id'];
            }
            $userId=array_unique($userId);
            foreach($list as $k=>$v){
               foreach($userId as $kk=>$vv){
                    if($vv==$v['id']){
                       $aa[$v['id']]=$v;
                    }
               }
            }
            foreach($aa as $k=>$v){
                $aa[$k]['uTime']=$this->gmtToIndiaTimeByMysql($v['uTime']);
                $aa[$k]['upTime']=$this->gmtToIndiaTimeByMysql($v['upTime']);
                $aa[$k]['ucTime']=$this->gmtToIndiaTimeByMysql($v['ucTime']);
                $aa[$k]['ucoTime']=$this->gmtToIndiaTimeByMysql($v['ucoTime']);
                $aa[$k]['ufTime']=$this->gmtToIndiaTimeByMysql($v['ufTime']);
            }
            $data = array_merge($column_name, $aa);
            $this->extendToExcel($data);
        }


//        dd(Db::name("user")->getLastSql());
        //总用户数
        $totalUser=Db::name("user")->alias('u')
            ->join('user_personalinfo up','u.id = up.user_id',"RIGHT")
            ->join('Usercertifies uc','u.userPhone = uc.phoneNumber',"RIGHT")
            ->join('UserCompCertifies uco','u.id = uco.userID',"RIGHT")
            ->join('userface uf','u.id = uf.user_id',"RIGHT")
//            ->whereOr($map)
            ->where($where)
            ->count("distinct u.id");
//        dd(Db::name("user")->getLastSql());
        $page = $list->render();
//        dd($list);die;
        $this->assign('data', $newList);
        $this->assign('page', $page);
        $this->assign('totalUser', $totalUser);
        return view();
    }

    /**
     * 完成人脸识别列表
     */
    public function facedList(){
        $url= Uri::HOST.Uri::GETALLFACE."?limitation=100000";
        $personal= $this->client->getArrayData($url);
        $personal=$personal['data'];
        $personalUser=[];
        $phoneTestPreg='/^1{7}[0-9]{3}/';
//        dd($personal);
        foreach($personal as $k=>$v){
            if(session('role') == 'admin'){
                if(!preg_match($phoneTestPreg,$v['user_phone'])){
                    $personalUser[]=$v['user_phone'];
                }
            }else if(session('role') == "testing"){
                if(preg_match($phoneTestPreg,$v['user_phone'])){
                    $personalUser[]=$v['user_phone'];
                }
            }
        }
        //获取短信推送模板
        $smsTmp=(new Smstmp())->getAppSmsTmp(1);
        $this->assign('smsTmp',$smsTmp);
        $get=$_GET;
        $query=[];
        $query['userPhone']=$personalUser;
        if(!empty($get['user_phone'])){
            $query['userPhone']=$get['user_phone'];
        }
        if(isset($get['sms_status'])){
            if($get['sms_status'] == 11){
                $query['admin_sms_status']=[0,1,2,3];
            }else{
                $query['admin_sms_status']=$get['sms_status'];
            }
        }else{
            $query['admin_sms_status']=[0,1,2,3];
        }
        if(isset($get['gender']) && $get['gender'] != ''){
            if($get['gender'] == 0){

            }else{
                $query['gender']=$get['gender'];
            }
        }
        if(!empty($get['startBirth'])){
            $query['birthDay']=[
                '$gte'=>$get['startBirth']
            ];
        }
        if(!empty($get['endBirth'])){
            $query['birthDay']=[
                '$lte'=>$get['endBirth']
            ];
        }
        if(!empty($get['startBirth']) && !empty($get['endBirth'])){
            $query['birthDay']=[
                '$gte'=>$get['startBirth'],
                '$lte'=>$get['endBirth']
            ];
        }
        if(!empty($get['signStart'])){
            $query['create_time']=[
                '$gte'=>$get['signStart']
            ];
        }
        if(!empty($get['signEnd'])){
            $query['create_time']=[
                '$lte'=>$get['signEnd']
            ];
        }
        if(!empty($get['signStart']) && !empty($get['signEnd'])){
            $query['create_time']=[
                '$gte'=>$get['signStart'],
                '$lte'=>$get['signEnd']
            ];
        }
        $query['limitation']=1000000;
        $countUrl=Uri::HOST.Uri::POSTUSERLIST;
        $totalCount =$this->client->getArrayData($countUrl,$query,3);

        if(isset($_GET['extend']) && $_GET['extend'] == 1){
            $column_name=[
                [
                    'ID',
                    'userPhone',
                    'status',
                    'inviteurl',
                    'invitor',
                    'admin_sms_status',
                    'create_time'
                ]
            ];
            $newTotalData=[];
            foreach($totalCount['data'] as $k=>$v){
                $newTotalData[]=[
                    'ID'=>$v['id'],
                    'userPhone'=>$v['userPhone'],
                    'status'=>$v['status'],
                    'inviteurl'=>$v['inviteurl'],
                    'invitor'=>$v['invitor'],
                    'admin_sms_status'=>$v['admin_sms_status'],
                    'create_time'=>date('Y-m-d H:i:s',strtotime($v['create_time']))
                ];
                if($v['admin_sms_status'] == 1){
                    $newTotalData[$k]['admin_sms_status']='pass';
                } elseif($v['admin_sms_status'] == 2){
                    $newTotalData[$k]['admin_sms_status']='nopass';
                }elseif($v['admin_sms_status'] == 3){
                    $newTotalData[$k]['admin_sms_status']='no SMS';
                }else{
                    $newTotalData[$k]['admin_sms_status']='no review';
                }
            }
            $data = array_merge($column_name, $newTotalData);
            $this->extendToExcel($data);
        }
        $p=empty(input('p'))?1:input('p');
        $startIndex=($p-1)*15;
        $query['limitation']=15;
        $query['offset']=$startIndex;
        $value = $this->client->getArrayData($countUrl,$query,3);
        if($value['code'] != 0){
            $value['data']=[];
        }
        foreach($value['data'] as $k=>$v){
            //查询个人认证信息
            $value['data'][$k]['create_time']=date('Y-m-d H:i:s',strtotime($v['create_time']));
            $userCerUrl=Uri::HOST.Uri::USERCERITYS."?phoneNumber=".$v['userPhone'];
            $userCerInfo=$this->client->getArrayData($userCerUrl);
            if(!empty($userCerInfo['data'])){
                $value['data'][$k]['userName']=$userCerInfo['data'][0]['firstname'].$userCerInfo['data'][0]['middlename'].$userCerInfo['data'][0]['lastname'];
            }else{
                $value['data'][$k]['userName']='';
            }
        }
        $pager=new Page(count($totalCount['data']),15,$p);
        $page=$pager->show();
        $this->assign('page',$page);
        $this->assign('data',$value['data']);
        $this->assign('totalCount',count($totalCount['data']));
        return view();
    }

    /**
     * 修改个人认证状态
     */
    public function updateUsercer(){
        $loan_check_id=$_POST['loan_check_id'];
        $usercerId=$_POST['usercerId'];
        $phone=$_POST['phone'];
        //更新loanCheck
        //查找loancheck
           $updateLoanUrl=Uri::HOST.Uri::UPDATELOANCHECK.$loan_check_id;
        $loanCheckData=$this->client->getArrayData($updateLoanUrl);
        $updateLoanCheckData=[
            "usercer_reject_count"=>$loanCheckData['data']['usercer_reject_count']+1,
            "usercer_reject"=>1
        ];
          $this->client->getArrayData($updateLoanUrl,$updateLoanCheckData,4);
       $url=Uri::HOST.Uri::UPDATEUSERCER.$usercerId;
        $data=[
            "valid"=>"REJECTED"
        ];
        $res=$this->client->getArrayData($url,$data,4);

        if($res['code'] == 0){
            //25分钟后发送短信和推送
            //查找该用户的信息
//            $userUrl=Uri::HOST.Uri::USERLIST."?userPhone=".$phone;
//            $userData=$this->client->getArrayData($userUrl);
//            $userData=$userData['data'][0];
//            $deviceId=$userData['deviceId'];
//            $timeUrl=Uri::TIMEEXE;
//            if(!empty($deviceId)){
//                //发送推送
//               $appUrl=Uri::HOST.Uri::SENDAPPSMS;
//                $timeData=[
//                       "callurl"=>$appUrl,
//                       "callMethod"=>"POST",
//                       "callparam"=>"{'reciver':[".$deviceId."],'msg':".\app\home\common\Smstmp::USERCERFAILED."}",
//                       "callTime"=>1500000,
//                ];
//                $this->client->getArrayData($timeUrl,$timeData,3);
//            }
//            //发送短信
//            $smsUrl=Uri::HOST.Uri::SENDSMS;
//            $timeSmsData=[
//                "callurl"=>$smsUrl,
//                "callMethod"=>"POST",
//                "callparam"=>"{'phone_num':".$phone.",'message':".\app\home\common\Smstmp::USERCERFAILED."}",
//                "callTime"=>1500000,
//            ];
//            $res=$this->client->getArrayData($timeUrl,$timeSmsData,3);
           return ["code"=>0,"msg"=>"0x200","data"=>"success"];
        }else{
            return $res;
        }
    }
    /**
     * 修改公司认证状态
     */
    public function updateComcer(){
        $loan_check_id=$_POST['loan_check_id'];
        $userComCerId=$_POST['userComCerId'];
        $phone=$_POST['phone'];
        //更新loanCheck
        //查找loancheck
        $updateLoanUrl=Uri::HOST.Uri::UPDATELOANCHECK.$loan_check_id;
        $loanCheckData=$this->client->getArrayData($updateLoanUrl);
        $updateLoanCheckData=[
            "usercer_reject_count"=>$loanCheckData['data']['usercer_reject_count']+1,
            "usercomcer_reject"=>1
        ];
        $this->client->getArrayData($updateLoanUrl,$updateLoanCheckData,4);
        $url=Uri::HOST.Uri::UPDATECOMPANYCER.$userComCerId;
        $data=[
            "valid"=>"REJECTED"
        ];
        $res=$this->client->getArrayData($url,$data,4);

        if($res['code'] == 0){
            //发送推送及短信
            //查找该用户的信息
//            $userUrl=Uri::HOST.Uri::USERLIST."?userPhone=".$phone;
//            $userData=$this->client->getArrayData($userUrl);
//            $userData=$userData['data'][0];
//            $deviceId=$userData['deviceId'];
//            $timeUrl=Uri::TIMEEXE;
//            if(!empty($deviceId)){
//                //发送推送
//                $appUrl=Uri::HOST.Uri::SENDAPPSMS;
//                $timeData=[
//                    "callurl"=>$appUrl,
//                    "callMethod"=>"POST",
//                    "callparam"=>"{'reciver':[".$deviceId."],'msg':".\app\home\common\Smstmp::COMCERFAILED."}",
//                    "callTime"=>1500000,
//                ];
//                $this->client->getArrayData($timeUrl,$timeData,3);
//            }
//            //发送短信
//            $smsUrl=Uri::HOST.Uri::SENDSMS;
//            $timeSmsData=[
//                "callurl"=>$smsUrl,
//                "callMethod"=>"POST",
//                "callparam"=>"{'phone_num':".$phone.",'message':".\app\home\common\Smstmp::COMCERFAILED."}",
//                "callTime"=>1500000,
//            ];
//            $this->client->getArrayData($timeUrl,$timeSmsData,3);
            return ["code"=>0,"msg"=>"0x200","data"=>"success"];
        }else{
            return $res;
        }
    }
    /**
     * 修改人脸识别状态
     */
    public function updateUserface(){
        $loan_check_id=$_POST['loan_check_id'];
        $userFaceId=$_POST['userFaceId'];
        $phone=$_POST['phone'];
        //更新loanCheck
        //查找loancheck
        $updateLoanUrl=Uri::HOST.Uri::UPDATELOANCHECK.$loan_check_id;
        $loanCheckData=$this->client->getArrayData($updateLoanUrl);
        $updateLoanCheckData=[
            "usercer_reject_count"=>$loanCheckData['data']['usercer_reject_count']+1,
            "userface_reject"=>1
        ];
        $this->client->getArrayData($updateLoanUrl,$updateLoanCheckData,4);
        $url=Uri::HOST.Uri::UPDATEUSERFACE.$userFaceId;
        $data=[
            "status"=>1
        ];
        $res=$this->client->getArrayData($url,$data,4);
        if($res['code'] == 0){
            //发送推送及短信
            //查找该用户的信息
//            $userUrl=Uri::HOST.Uri::USERLIST."?userPhone=".$phone;
//            $userData=$this->client->getArrayData($userUrl);
//            $userData=$userData['data'][0];
//            $deviceId=$userData['deviceId'];
//            $timeUrl=Uri::TIMEEXE;
//            if(!empty($deviceId)){
//                //发送推送
//                $appUrl=Uri::HOST.Uri::SENDAPPSMS;
//                $timeData=[
//                    "callurl"=>$appUrl,
//                    "callMethod"=>"POST",
//                    "callparam"=>"{'reciver':[".$deviceId."],'msg':".\app\home\common\Smstmp::FACEFAILED."}",
//                    "callTime"=>1500000,
//                ];
//                $this->client->getArrayData($timeUrl,$timeData,3);
//            }
//            //发送短信
//            $smsUrl=Uri::HOST.Uri::SENDSMS;
//            $timeSmsData=[
//                "callurl"=>$smsUrl,
//                "callMethod"=>"POST",
//                "callparam"=>"{'phone_num':".$phone.",'message':".\app\home\common\Smstmp::FACEFAILED."}",
//                "callTime"=>1500000,
//            ];
//            $this->client->getArrayData($timeUrl,$timeSmsData,3);
            return ["code"=>0,"msg"=>"0x200","data"=>"success"];
        }else{
            return $res;
        }
    }

    /**
     * 用户统计
     */
    public function countEchart(){
        $data=Db::table("analyse_user")->where('name','day')->order("create_time DESC")->find();
        $this->assign('data',$data);
        return view();
    }

    /**
     * 修改认证状态发送短信和推送
     */
    public function sendSms(){
        $phone=$_POST['phone'];
        $type=$_POST['type'];
        if($type == 1){
            $sms="Dear Customer, in order to be qualified for loan. Make sure your Aadhaar photos are clear to indentify the No. and name. Please go to [Certification] to complete Personal Certification again. Thank you.";
            $push="Dear Customer, in order to be qualified for loan. Make sure your Aadhaar photos are clear to indentify the No. and name. Please go to [Certification] to complete Personal Certification again. Thank you.";
        }else if($type == 2){
            $sms="Dear Customer, In order to verify your qualification for loan, please go to the Certification Center to complete Company Certification part. Thank you.FlashCash.";
            $push="Dear Customer, In order to verify your qualification for loan, please go to the Certification Center to complete Company Certification part. Thank you.FlashCash.";
        }else if($type == 3){
            $sms="Dear Customer, In order to verify your qualification for loan, please go to the Certification Center to complete Face Recognition part. Thank you.FlashCash.";
            $push="Dear Customer, In order to verify your qualification for loan, please go to the Certification Center to complete Face Recognition part. Thank you.FlashCash.";
        }
        //发送推送及短信
        //查找该用户的信息
        $userUrl=Uri::HOST.Uri::USERLIST."?userPhone=".$phone;
        $userData=$this->client->getArrayData($userUrl);
        $userData=$userData['data'][0];
        $deviceId=$userData['deviceId'];
        if(!empty($deviceId)){
            //发送推送
            $appUrl=Uri::HOST.Uri::SENDAPPSMS;
            $appData=[
                "reciver"=>[$deviceId],
                "msg"=>$sms
            ];
            $this->client->getArrayData($appUrl,$appData,3);
        }
        //发送短信
        $smsUrl=Uri::HOST.Uri::SENDSMS;
        $smsData=[
            "phone_num"=>$phone,
            "message"=>$push
        ];
        $ee=$this->client->getArrayData($smsUrl,$smsData,3);
        return ["code"=>0,"msg"=>"0x200","data"=>"success"];
    }

}